package com.enation.app.javashop.core.client.fallback.goods;

import com.enation.app.javashop.core.client.feignimpl.goods.GoodsIndexClientFeignImpl;
import com.enation.app.javashop.core.handler.BaseFallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 商品索引熔断 fallback factory
 * @author kingapex
 * @version 1.0
 * @data 2022/5/28 14:16
 **/
@Component
public class GoodsIndexClientFallbackFactory  extends BaseFallbackFactory<GoodsIndexClientFeignImpl> {
    @Override
    protected GoodsIndexClientFeignImpl fallback() {
        return new GoodsIndexClientFallback();
    }

    /**
     * 商品索引熔断
     *
     * @author zh
     * @version v7.0
     * @date 18/9/27 下午3:07
     * @since v7.0
     */
    @Component
    public static class GoodsIndexClientFallback implements GoodsIndexClientFeignImpl {
        private final Logger logger = LoggerFactory.getLogger(getClass());

        @Override
        public void addIndex(Map goods) {
            logger.error("将某个商品添加到索引错误");
        }

        @Override
        public void updateIndex(Map goods) {
            logger.error("更新商品到索引错误");
        }

        @Override
        public void deleteIndex(Map goods) {
            logger.error("删除商品索引错误");
        }

        @Override
        public boolean addAll(List<Map<String, Object>> list, int index) {
            logger.error("初始化索引错误");
            return false;
        }
    }
}
